﻿

using System;
using System.Collections.Generic;

namespace BusinessLayer
{
    /// <summary>
    /// The BL reader.
    /// </summary>
    public class Reader<T> where T : BusinessEntity, new()
    {
        /// <summary>
        /// The DAL reader.
        /// </summary>
        private DataAccessLayer.Reader _reader;

        /// <summary>
        /// Gets the current.
        /// </summary>
        public T Current { get; private set; }

        /// <summary>
        /// Initializes a new instance of the <see cref="Reader{T}"/> class.
        /// </summary>
        public Reader(DataAccessLayer.Reader reader)
        {
            this._reader = reader;
            Current = new T();
        }

        /// <summary>
        /// Gets the next.
        /// </summary>
        public bool Read()
        {
            if (this._reader.Read())
            {
                this.Current = new T();
                this.Current.Initialize(this._reader.Current);
                return true;
            }
            else
                return false;
        }

        /// <summary>
        /// Close the reader.
        /// </summary>
        public void Close()
        {
            this._reader.Close();
        }


    }
}
